package com.neulogistics.core.customercenter.infrastructure.persistence.repository;

import com.neulogistics.core.customercenter.domain.model.aggregate.Order;
import com.neulogistics.core.customercenter.domain.repository.IOrderRepository;
import com.neulogistics.core.customercenter.infrastructure.persistence.converter.OrderEntityPOConverter;
import com.neulogistics.core.customercenter.infrastructure.persistence.orm.po.OrderPO;
import com.neulogistics.core.customercenter.infrastructure.persistence.orm.service.IOrderPOService;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

@Repository
public class OrderRepository implements IOrderRepository {
    @Resource
    IOrderPOService orderPOService;

    @Override
    public void save(Order order) {
        OrderPO orderPO = OrderEntityPOConverter.entityToPO(order);
        // 如果新建， 存入creator_id
        // TODO 获取creatorId
        orderPO.setCreatorId(1);
        orderPOService.saveOrUpdate(orderPO);
    }

    @Override
    public Order findById(Long id) {
        OrderPO orderPO = orderPOService.getById(id);
        Order order = OrderEntityPOConverter.POToEntity(orderPO);
        return order;
    }

    @Override
    public void deleteById(Long id) {
        orderPOService.removeById(id);
    }
}
